﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IChessEngine;

namespace ChessEngine.Basic
{
    public class ChsMovement : IChsMovement
    {
        private IChsSquare source = null;
        private IChsSquare target = null;
        private int? difX = null;
        private int? difY = null;
        private EChsPieceType  promotingType = EChsPieceType.NONE;
        public ChsMovement(IChsSquare _source, IChsSquare _target)
        {
            source = _source;
            target = _target;
            promotingType = EChsPieceType.NONE;
        }
        public ChsMovement(IChsSquare _source, IChsSquare _target, EChsPieceType _promotingType)
        {
            source = _source;
            target = _target;
            promotingType = _promotingType;
        }
        public ChsMovement(IChsMovement _movement)
        {
            source = _movement.Source;
            target = _movement.Target;
            promotingType = _movement.PromotingType;
        }
        public IChsSquare Source
        {
            get { return source; }
        }

        public IChsSquare Target
        {
            get { return target; }
        }

        public int DifX
        {
            get 
            { 
                if(!difX.HasValue)
                    difX = target.X - source.X;
                return difX.Value;

            }
        }

        public int DifY
        {
            get
            {
                if (!difY.HasValue)
                    difY = target.Y - source.Y;
                return difY.Value;

            }
        }
        public EChsPieceType PromotingType
        {
            get { return promotingType; }
        }
    }
}
